﻿<Window x:Class="EmailClientWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ViewModel="clr-namespace:EmailClientWPF.ViewModels" 
        xmlns:Views="clr-namespace:EmailClientWPF.Views"
        xmlns:converters="clr-namespace:EmailClientWPF.Converters"
        Title="MainWindow" Height="auto" Width="auto">
    <Window.DataContext>
        <ViewModel:AppViewModel />
    </Window.DataContext>
    <Window.Resources>
        <DataTemplate            
            DataType="{x:Type ViewModel:LoginRegisterFormViewModel}">
            <Views:LoginRegisterFormView/>
        </DataTemplate>
        <DataTemplate            
            DataType="{x:Type ViewModel:NewMessageViewModel}">
            <Views:NewMessageView/>
        </DataTemplate>
        <DataTemplate            
            DataType="{x:Type ViewModel:InboxViewModel}">
            <Views:InboxView/>
        </DataTemplate>
        <converters:BoolToVisibilityConverter x:Key="boolToVisibilityConverter"/>
    </Window.Resources>
        <DockPanel>
            <StackPanel Name="HeaderContainer"
                        Visibility="{Binding Path=LoggedInUser,Converter={StaticResource boolToVisibilityConverter}}"
                        DockPanel.Dock="Left"
                        Margin="10">
                <ItemsControl ItemsSource="{Binding ViewModels}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Button Content="{Binding Name}"
                                    Command="{Binding Path=DataContext.ChangeViewModel, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                                    CommandParameter="{Binding}"
                                    Margin="0 0 0 5"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <Button Command="{Binding Logout}">Logout</Button>
        </StackPanel>
            <ContentControl DockPanel.Dock="Right"            
                            Content="{Binding CurrentViewModel}" 
                            Margin="0 10 0 0"/>
        </DockPanel>
</Window>
